package timer;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;

/**
 * Created by Ming on 2017/6/3.
 */
public class CancelTest {
    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();

        MytTimerTask timerTask1 = new MytTimerTask("task1");
        MytTimerTask timerTask2 = new MytTimerTask("task2");

        Date startTime = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(simpleDateFormat.format(startTime));

        timer.schedule(timerTask1, 3000, 2000);
        timer.schedule(timerTask2, 1000, 2000);
        Thread.sleep(2000);
        Date cancelTime = new Date();
        System.out.println(timer.purge());
        timerTask1.cancel();
        System.out.println(timer.purge());
    }
}
